<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id="first">
    <select name="" id="choose">
        <option value="add">+</option>
        <option value="down">-</option>
        <option value="ride">x</option>
        <option value="divide">÷</option>
    </select>
    <input type="text" id="second">
    <button id="btn">=</button>
    <input type="text" id="result" disabled>

    <!-- 简易计算器作业 -->
    <script>
        btn.onclick = function () {
            // 这两个值要写在btn.onclick里面才能在点击的时候重新获取一遍他们的值
            // 假如写在外面就把他们的值定死了，点击btn也获取不了
            var n1 = first.value - 0
            var n2 = second.value - 0
            switch (choose.value) {
                case "add":
                    var res = n1 + n2;
                    break;
                case "down":
                    var res = n1 - n2;
                    break;
                case "ride":
                    var res = n1 * n2;
                    break;
                case "divide":
                    var res = n1 / n2;
                    break;
                default:
                    break;
            }
            result.value = res
        }
    </script>


    <!-- if判断第几天作业 -->
    <script>
        // 准备年月日变量
        var year = 2020;
        var month = 1;
        var day = 31;

        // 准备变量接收结果
        var res = 0;
        if (month > 1) res += 31;
        if (month > 2) {
            // month>2是三月份，此时要判断3月份+二月份的天数是闰年29天还是平年28天
            if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
                res += 29
            } else {
                res += 28
            }
        }
        if (month > 3) {
            res += 31
        }
        if (month > 4) {
            res += 30
        }
        if (month > 5) {
            res += 31
        }
        if (month > 6) {
            res += 30
        }
        if (month > 7) {
            res += 31
        }
        if (month > 8) {
            res += 31
        }
        if (month > 9) {
            res += 30
        }
        if (month > 10) {
            res += 31
        }
        if (month > 11) {
            res += 30
        }
        res += day
        console.log(res);
    </script>
</body>

</html>